//
//  CXDestinationDetailCollectionViewCell.m
//  Travel
//
//  Created by dllo on 15/11/30.
//  Copyright © 2015年 doll. All rights reserved.
//

#import "CXDestinationDetailCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "CXDestinationModel.h"
#import "UIImage+GIF.h"
#import "StarView.h"

@interface CXDestinationDetailCollectionViewCell ()

@property (nonatomic, retain)UIImageView *img;
@property (nonatomic, retain)UILabel *label;
@property (nonatomic, retain) StarView *star;

@end

@implementation CXDestinationDetailCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}
- (void)createView
{
    self.img = [[UIImageView alloc]init];
    [self.contentView addSubview:self.img];
    self.img.layer.cornerRadius = 10;
    self.img.clipsToBounds = YES;
    
    self.label = [[UILabel alloc]init];
    self.label.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
    self.label.textColor = [UIColor whiteColor];
    self.label.shadowColor = [UIColor grayColor];
    [self.img addSubview:self.label];
    
    
}
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [super layoutSubviews];
    
    self.contentView.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
   
    self.img.frame = CGRectMake(0, 0, layoutAttributes.frame.size.width, layoutAttributes.frame.size.height);
    
    self.label.frame  = CGRectMake(10, self.img.frame.size.height - 40 , layoutAttributes.frame.size.width - 20, 20);
    
}


- (void)setModel_destination:(CXDestinationModel *)model_destination
{
    _model_destination = model_destination;
    [self.img sd_setImageWithURL:[NSURL URLWithString:self.model_destination.cover_s] placeholderImage:[UIImage sd_animatedGIFNamed:@"load"]];
    self.label.text = self.model_destination.name;
    
}

- (void)setHasStar:(BOOL)hasStar
{
    _hasStar = hasStar;
    if (hasStar) {
        self.star = [[StarView alloc] initWithFrame:CGRectMake(10, self.contentView.frame.size.height - 20, 15 * 5 + 8, 15) rating:_model_destination.rating.floatValue];
        [self.img addSubview:self.star];
    }
}


@end
